package com.jinke.api.modules.ums.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jinke.api.common.api.CommonPage;
import com.jinke.api.common.api.CommonResult;
import com.jinke.api.modules.app.model.SysMessage;
import com.jinke.api.modules.app.request.AdminMessageQueryRequest;
import com.jinke.api.modules.app.request.MessageReadRequest;
import com.jinke.api.modules.app.request.SysMessageCreateRequest;
import com.jinke.api.modules.app.response.SysMessageVO;
import com.jinke.api.modules.app.service.SysMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(tags = "后台消息管理")
@Tag(name = "后台消息管理", description = "后台消息管理")
@RequestMapping("/admin/sysMessage")
@Slf4j
public class AdminSysMessageController {

    @Resource
    SysMessageService sysMessageService;


    @ApiOperation("删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult delete(@RequestBody MessageReadRequest request) {
        return sysMessageService.deleteSysMessage(request);
    }

    @ApiOperation("创建消息")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult create(@RequestBody SysMessageCreateRequest request) {
        return sysMessageService.create(request);
    }

    @ApiOperation("消息列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<SysMessage>> list(AdminMessageQueryRequest request) {
        Page<SysMessage> list = sysMessageService.listSysMessage(request);
        return CommonResult.success(CommonPage.restPage(list));
    }

/*
    @ApiOperation("工单回复")
    @RequestMapping(value = "/reply", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult reply(@RequestBody QuestionReplyRequest questionReplyRequest) {
        questionReplyRequest.setReplyType(ReplyType.REPLY);
        return sysMessageService.reply(questionReplyRequest);
    }

    @ApiOperation("根据ID获取工单详情")
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<UserQuestionVO> getItem( QuestionDetailRequest questionDetailRequest) {
        UserQuestionVO detail = sysMessageService.detail(questionDetailRequest);
        return CommonResult.success(detail);
    }

    @ApiOperation("关闭")
    @RequestMapping(value = "/close", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<UserQuestionVO> close(@RequestBody  QuestionDetailRequest questionDetailRequest) {
        return sysMessageService.close(questionDetailRequest);
    }

    @ApiOperation("重新打开")
    @RequestMapping(value = "/reopen", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<UserQuestionVO> reopen(@RequestBody QuestionReplyRequest questionReplyRequest) {
        return sysMessageService.reopen(questionReplyRequest);
    }

    @ApiOperation("工单列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<UserQuestionVO>> list(QuestionQueryRequest request) {

        Page<UserQuestionVO> list = sysMessageService.list(request);
        return CommonResult.success(CommonPage.restPage(list));
    }*/

}
